package net.junaoki.persistence;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class HibernateSessionRequestFilter implements Filter{

    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        // HibernateUtil.getCurrentSession();
        try{
            chain.doFilter(servletRequest, servletResponse);
        }finally{
            HibernateUtil.closeCurrentSession();
        }

    }

    @Override
    public void destroy() {
    }

}
